#include <algorithm>
#include <iostream>
#include <vector>

class Point
{
public:
	std::vector<double> x;
	int num;

	Point(int n): num(n) {}
	Point(int d, int n): x(d), num(n) {}

	int dim()
	{
		return x.size();
	}

	double operator[](int i)
	{
		return x[i];
	}
};

class Comparator
{
public:
	int f;
	Comparator(int f_)
	{
		f = f_;
	}

	bool operator()(Point p1, Point p2)
	{
		for (int i = f; i < f + p1.dim(); i++) 
		{
			int n = i % p1.dim();

			if (p1[n] < p2[n])
				return true;
			if (p1[n] > p2[n])
				return false;
		}
		return true;
	}
};

int main() 
{
	using std::cin;
	using std::cout;
	
	int d, n, m;
	cin >> d >> n >> m;

	std::vector<Point> points;
	for (int i = 0; i < n; i++) 
	{
		Point p(d, i + 1);
		for (int j = 0; j < d; j++)
		{
			cin >> p.x[j];
		}
		points.push_back(p);
	}

	std::sort(points.begin(), points.end(), Comparator(0));

	for (int i = 0; i < m; i++)
	{
		Point l(d, -1), r(d, -1);
		
		for (int j = 0; j < d; j++)
		{
			cin >> l.x[j];
		}
		for (int j = 0; j < d; j++)
		{
			cin >> r.x[j];
		}

		std::vector<Point> temp = points;
		for (int dim = 0; dim < d - 1; dim++)
		{
			std::vector<Point> temp2;

			size_t num = 0;
			while (num < temp.size() && temp[num][dim] < l[dim])
			{
				num++;
			}
			while (num < temp.size() && temp[num][dim] <= r[dim])
			{
				temp2.push_back(temp[num]);
				num++;
			}

			std::sort(temp2.begin(), temp2.end(), Comparator(dim + 1));
			temp = temp2;
		}

		size_t num = 0;
		while (num < temp.size() && temp[num][d - 1] < l[d - 1])
		{
			num++;
		}
		int ans = 0;
		while (num + ans < temp.size() && temp[num + ans][d - 1] <= r[d - 1])
		{
			ans++;
		}

		cout << ans << "\n";
		for (int i = 0; i < ans; i++) 
		{
			cout << temp[num + i].num << " ";
		}
		cout << "\n";
	}
}